package jdbctest2;

import java.sql.*;

public class JDBCSQLTest1 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()) {
            String sql = "SELECT *\n" +
                    "    FROM sanguo\n" +
                    "WHERE country = ?\n" +
                    "ORDER BY attack DESC ";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"蜀");
            ResultSet rs = ps.executeQuery();
            while(rs.next()){
                System.out.print(rs.getInt("id"));
                System.out.print(rs.getString("name"));
                System.out.print(rs.getString("gender"));
                System.out.print(rs.getString("country"));
                System.out.print(rs.getInt("attack"));
                System.out.print(rs.getInt("defense"));
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
